package jhta;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.util.Date;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import javax.swing.text.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

import net.sourceforge.jdatepicker.impl.JDatePanelImpl;
import net.sourceforge.jdatepicker.impl.JDatePickerImpl;
import net.sourceforge.jdatepicker.impl.UtilDateModel;

public class BookUpdate extends JInternalFrame {
	JavaDBConnection jdbc;
	Connection conn;
	
	int codeNo;
	int memberNo;
	int tVolume;
	int volume;
	
	SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
	
	DefaultTableModel model;
	MyTableRender render;
	TableRowSorter<TableModel> tSoter;
	
	String[] t = {"대분류", "소분류", "도서번호", "도서명"};
	
	private JComboBox comboBox;
	private JTextField txtInput;
	private JButton btnSearch;
	private JScrollPane scrollPane;
	private JTable table;
	private JLayeredPane layeredPane;
	private JLabel label;
	private JLabel label_2;
	private JComboBox comboBox_1;
	private JLayeredPane layeredPane_1;
	private JLabel lblEhtjqjsgh;
	private JLabel label_9;
	private JLabel label_10;
	private JLabel label_11;
	private JLabel label_12;
	private JTextField txtNo;
	private JTextField txtName;
	private JTextField txtAuthor;
	private JTextField txtPublisher;
	private JButton btnUpdate;
	private JButton btnDelete;
	private JLayeredPane layeredPane_2;
	private JLabel label_3;
	private JComboBox comboBox_2;
	private JLabel label_4;
	private JTextField txtBig;
	private JLabel label_1;
	private JLabel label_5;
	private JSpinner spinnerTvolume;
	private JLabel label_6;
	private JSpinner spinnerVolume;
	private JTextField txtPdate;
	private JTextField txtRdate;
	private JDatePickerImpl datePicker;
	private JDatePickerImpl datePicker1;
	
	public BookUpdate() {
		super("도서 정보 조회 및 수정", true, true, true, true);
		addComponentListener(new ComponentAdapter() {
			@Override
			public void componentHidden(ComponentEvent e) {
				clear();
			}
		});
		addInternalFrameListener(new InternalFrameAdapter() {
			@Override
			public void internalFrameActivated(InternalFrameEvent arg0) {
				comboBoxAdminSetting();
				comboBoxSmallCodeSetting();
			}
		});

		setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
		setBounds(100, 100, 713, 539);
		getContentPane().setLayout(null);
		getContentPane().add(getComboBox());
		getContentPane().add(getTxtInput());
		getContentPane().add(getBtnSearch());
		getContentPane().add(getScrollPane());
		getContentPane().add(getLayeredPane_1());
		getContentPane().add(getLayeredPane_1_1());
		getContentPane().add(getLayeredPane_2());
		getContentPane().add(getBtnUpdate());
		getContentPane().add(getBtnDelete());
		getContentPane().add(getLabel_4_1());
		
		jdbc = new JavaDBConnection();
		conn = jdbc.getConn();
		
		clear();
	}
	
	// DB에서 소분류 검색하고 콤보박스에 채워줌
	public void comboBoxSmallCodeSetting(){
		comboBox_1.removeAllItems();
		String sql = "select distinct code_name from code "
				   + "where code_big = 'A1' and code_small is not null";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			if(pstmt.executeUpdate() > 0){
				ResultSet rs = pstmt.executeQuery();
				
				while(rs.next())comboBox_1.addItem(rs.getString("code_name"));
				
				rs.close();
			}else{ 
				JOptionPane.showMessageDialog(null, "소분류 항목을 불러올 수 없습니다."); 
			}
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
	}
	
	// DB에서 관리자 목록을 검색하고 콤보박스에 뿌려줌
	public void comboBoxAdminSetting(){
		comboBox_2.removeAllItems();
		String sql = "select b.name from bookmember b inner join code c "
				   + "on b.code_no = c.code_no "
				   + "where c.code_big = ?";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, "A2");

			if(pstmt.executeUpdate() > 0){
				ResultSet rs = pstmt.executeQuery();
				
				comboBox_2.addItem(Main.USER_NAME);
				while(rs.next()) comboBox_2.addItem(rs.getString(1));

				rs.close();
			}else{
				JOptionPane.showMessageDialog(null, "관리자 항목을 불러올 수 없습니다.");
			}
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
	}
	
	// 테이블 항목을 선택했을 때 정보를 화면에 뿌려줌
	public void infoSetting(int bookNo){
		String sql = "select * from book where no = ?";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, bookNo);
			
			if(pstmt.executeUpdate() > 0){
				ResultSet rs = pstmt.executeQuery();

				if(rs.next()){
					txtNo.setText(rs.getString(1));
					txtName.setText(rs.getString(2));
					txtAuthor.setText(rs.getString(3));
					txtPublisher.setText(rs.getString(4));
					txtPdate.setText(sd.format(rs.getDate(5)));
					txtRdate.setText(sd.format(rs.getDate(6)));
					
					tVolume = rs.getInt(7);
					volume = rs.getInt(8);
					txtBig.setText("도서");

					spinnerTvolume.setValue(tVolume);
					spinnerVolume.setValue(volume);
					
					comboBoxSmallCodeSetting();
					comboBoxAdminSetting();
					
					setAdmin(rs.getInt(9)); // 책을 등록했던 관리자로 콤보박스 세팅
					setCode(rs.getInt(10)); // 책을 등록했던 분류코드로 콤보박스 세팅
					
					comboBox_1.setEnabled(true);
					comboBox_2.setEnabled(true);
					spinnerTvolume.setEnabled(true);
				}
				rs.close();
			}else{
				JOptionPane.showMessageDialog(null, "테이블 정보를 불러올 수 없습니다.");
			}
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
	}
	
	// 책을 등록했던 관리자로 콤보박스 세팅
	public void setAdmin(int n){
		String sql = "select name from bookmember where no = ?";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, n);
			
			if(pstmt.executeUpdate() > 0){
				ResultSet rs = pstmt.executeQuery();
				if(rs.next()) comboBox_2.setSelectedItem(rs.getString(1));
				rs.close();
			}else{
				JOptionPane.showMessageDialog(null, "관리자를 불러올 수 없습니다.");
			}
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
	}
	
	// 책을 등록했던 관리자로 콤보박스 세팅
	public void setCode(int n){
		String sql = "select code_name from code where code_no = ?";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, n);
			
			if(pstmt.executeUpdate() > 0){
				ResultSet rs = pstmt.executeQuery();
				if(rs.next()) comboBox_1.setSelectedItem(rs.getString(1));
				rs.close();
			}else{
				JOptionPane.showMessageDialog(null, "소분류를 불러올 수 없습니다.");
			}
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
	}
	
	// 소분류를 선택했을 때 코드번호(code_no)를 검색해서 codeNo 변수에 저장
	public int getCodeNo(){
		String sql = "select code_no from code where code_big = ? and code_name = ?";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, "A1");
			pstmt.setString(2, comboBox_1.getSelectedItem().toString());
			
			if(pstmt.executeUpdate() > 0){
				ResultSet rs = pstmt.executeQuery();
				if(rs.next()) codeNo = rs.getInt(1);
				rs.close();
			}else{
				JOptionPane.showMessageDialog(null, "분류번호를 불러올 수 없습니다.");
			}
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
		
		return codeNo;
	}
	
	// 관리자를 선택했을 때 회원번호(member_no)를 검색해서 저장 memberNo 변수에 저장
	public int getMemberNo(){
		String sql = "select no from bookmember where name = ?";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, comboBox_2.getSelectedItem().toString());
			
			if(pstmt.executeUpdate() > 0){
				ResultSet rs = pstmt.executeQuery();
				if(rs.next()) memberNo = rs.getInt(1);
				rs.close();
			}else{
				JOptionPane.showMessageDialog(null, "관리자 번호를 불러올 수 없습니다.");
			}
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
		
		return memberNo;
	}
	
	// 콤보박스의 '전체'를 선택하고 검색했을 경우
	public void searchDB(){
		clear();
		
		String find = "%" + txtInput.getText() + "%";
		String sql = "";
		try{
			PreparedStatement pstmt = null;
			if(comboBox.getSelectedIndex() == 0){
				sql = "select c.code_name, b.no, b.name from book b inner join code c "
					   + "on b.code_no = c.code_no "
					   + "where c.code_name like ? or b.no like ? or b.name like ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, find);
				pstmt.setString(2, find);
				pstmt.setString(3, find);
			}else if(comboBox.getSelectedIndex() == 1){
				sql = "select c.code_name, b.no, b.name from book b inner join code c "
						   + "on b.code_no = c.code_no "
						   + "where c.code_name like ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, find);
			}else if(comboBox.getSelectedIndex() == 2){
				sql = "select c.code_name, b.no, b.name from book b inner join code c "
						   + "on b.code_no = c.code_no "
						   + "where b.name like ?";
				pstmt = conn.prepareStatement(sql);
				pstmt.setString(1, find);
			}
			
			if(pstmt.executeUpdate() > 0){
				ResultSet rs = pstmt.executeQuery();

				while(rs.next()){
					Vector v = new Vector();
					v.add("도서");
					v.add(rs.getString(1));
					v.add(rs.getString(2));
					v.add(rs.getString(3));
					
					model.addRow(v);
				}
				rs.close();
			}else{
				JOptionPane.showMessageDialog(null, "검색된 정보가 없습니다.");
			}
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
	}
	
	// '수정'버튼을 눌렀을 경우 데이터베이스 update
	public void updateDB(){
		String sql = "update book set name = ?, author = ?, publisher = ?, " 
				   + "pdate = to_date(?, 'yyyy-mm-dd'), rdate = to_date(?, 'yyyy-mm-dd'), " 
				   + "member_no = ?, code_no = ?, tvolume = ?, volume = ? " 
				   + "where no = ?";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, txtName.getText());
			pstmt.setString(2, txtAuthor.getText());
			pstmt.setString(3, txtPublisher.getText());
			pstmt.setString(4, txtPdate.getText());
			pstmt.setString(5, txtRdate.getText());
			pstmt.setInt(6, getMemberNo());
			pstmt.setInt(7, getCodeNo());
			pstmt.setInt(8, tVolume);
			pstmt.setInt(9, volume);
			pstmt.setInt(10, Integer.parseInt(txtNo.getText()));
			
			if(pstmt.executeUpdate() > 0){
				JOptionPane.showMessageDialog(null, "데이터가 수정되었습니다.");
				clear();
				searchDB();
			}
			
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
	}
	
	// '삭제'버튼을 눌렀을 경우 데이터베이스 delete
	public void deleteDB(){
		String sql = "delete from book where no = ?";
		
		try{
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, Integer.parseInt(txtNo.getText()));
			
			if(pstmt.executeUpdate() > 0){
				JOptionPane.showMessageDialog(null, "데이터가 삭제되었습니다.");
				clear();
				searchDB();
			}			
			pstmt.close();
		}catch(Exception ex){ex.getStackTrace();}
	}
	
	// 초기화
	public void clear(){
		txtNo.setText("");
		txtName.setText("");
		txtAuthor.setText("");
		txtPublisher.setText("");
		txtBig.setText("");	
		txtRdate.setText("");
		txtPdate.setText("");
		
		comboBox_1.removeAllItems();
		comboBox_1.setEnabled(false);
		comboBox_2.removeAllItems();
		comboBox_2.setEnabled(false);
		spinnerTvolume.setValue(0);
		spinnerVolume.setValue(0);
		spinnerTvolume.setEnabled(false);
		model.setNumRows(0);
	}
	private JComboBox getComboBox() {
		if (comboBox == null) {
			comboBox = new JComboBox();
			comboBox.setBorder(null);
			comboBox.setModel(new DefaultComboBoxModel(new String[] {"전체", "소분류", "도서명"}));
			comboBox.setBounds(12, 11, 112, 25);
		}
		return comboBox;
	}
	public JTextField getTxtInput() {
		if (txtInput == null) {
			txtInput = new JTextField();
			txtInput.addKeyListener(new KeyAdapter() {
				@Override
				public void keyPressed(KeyEvent e) {
					if(e.getKeyCode() == KeyEvent.VK_ENTER){
						searchDB();
					}
				}
			});
			txtInput.setBounds(136, 11, 424, 25);
			txtInput.setColumns(10);
		}
		return txtInput;
	}
	private JButton getBtnSearch() {
		if (btnSearch == null) {
			btnSearch = new JButton("조회");
			btnSearch.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					searchDB();
				}
			});
			btnSearch.setBounds(572, 8, 112, 30);
		}
		return btnSearch;
	}
	private JButton getBtnUpdate() {
		if (btnUpdate == null) {
			btnUpdate = new JButton("수정");
			btnUpdate.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(!txtNo.getText().equals("")){
						updateDB();
					}
				}
			});
			btnUpdate.setPreferredSize(new Dimension(100, 50));
			btnUpdate.setBounds(412, 456, 130, 40);
		}
		return btnUpdate;
	}
	private JButton getBtnDelete() {
		if (btnDelete == null) {
			btnDelete = new JButton("삭제");
			btnDelete.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(!txtNo.getText().equals("")){
						deleteDB();
					}
				}
			});
			btnDelete.setBounds(554, 456, 130, 40);
		}
		return btnDelete;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBackground(Color.WHITE);
			scrollPane.getViewport().setBackground(Color.white);
			scrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
			scrollPane.setBounds(12, 46, 672, 219);
			scrollPane.setViewportView(getTable());
		}
		return scrollPane;
	}
	private JTable getTable() {
		if (table == null) {
			model = new DefaultTableModel(t, 0){
				// 테이블의 값을 변경하지 못하도록 설정
				public boolean isCellEditable(int i, int c){
					return false;
				}
			};
			table = new JTable(model);
			table.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					int row = table.getSelectedRow();
					
					infoSetting(Integer.parseInt(table.getValueAt(row, 2).toString()));
				}
			});
			
			// 헤더 가운데 정렬
			DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer();
	        renderer.setHorizontalAlignment(0);
	        
			tSoter = new TableRowSorter(model);
			table.setRowSorter(tSoter);
			
			char[] c = {'c','c','c','l'};
			int[] w = {60,60,60,200};
			render = new MyTableRender(table, c, w);
		}
		return table;
	}
	private JLayeredPane getLayeredPane_1() {
		if (layeredPane == null) {
			layeredPane = new JLayeredPane();
			layeredPane.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null), "\uBD84\uB958", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
			layeredPane.setBounds(410, 275, 274, 84);
			layeredPane.add(getLabel_8());
			layeredPane.add(getLabel_2_1());
			layeredPane.add(getComboBox_3_1());
			layeredPane.add(getTxtBig());
		}
		return layeredPane;
	}
	private JLabel getLabel_8() {
		if (label == null) {
			label = new JLabel("대  분  류 :");
			label.setForeground(Color.BLUE);
			label.setHorizontalAlignment(SwingConstants.RIGHT);
			label.setBounds(-4, 22, 67, 15);
		}
		return label;
	}
	private JLabel getLabel_2_1() {
		if (label_2 == null) {
			label_2 = new JLabel("소  분  류 :");
			label_2.setHorizontalAlignment(SwingConstants.RIGHT);
			label_2.setBounds(-4, 52, 67, 15);
		}
		return label_2;
	}
	private JComboBox getComboBox_3_1() {
		if (comboBox_1 == null) {
			comboBox_1 = new JComboBox();
			comboBox_1.setBounds(75, 47, 187, 25);
		}
		return comboBox_1;
	}
	private JLayeredPane getLayeredPane_1_1() {
		if (layeredPane_1 == null) {
			layeredPane_1 = new JLayeredPane();
			layeredPane_1.setLayout(null);
			layeredPane_1.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null), "\uB3C4\uC11C\uC815\uBCF4", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
			layeredPane_1.setBounds(124, 275, 274, 225);
			layeredPane_1.add(getLabel_8_1());
			layeredPane_1.add(getLabel_9());
			layeredPane_1.add(getLabel_10());
			layeredPane_1.add(getLabel_11());
			layeredPane_1.add(getLabel_12());
			layeredPane_1.add(getTxtNo());
			layeredPane_1.add(getTxtName());
			layeredPane_1.add(getTxtAuthor());
			layeredPane_1.add(getTxtPublisher());
			layeredPane_1.add(getLabel_5());
			layeredPane_1.add(getSpinnerTvolume());
			layeredPane_1.add(getLabel_6());
			layeredPane_1.add(getSpinnerVolume());
			layeredPane_1.add(getDatePicker());
			layeredPane_1.add(getTxtPdate());
		}
		return layeredPane_1;
	}
	private JLabel getLabel_8_1() {
		if (lblEhtjqjsgh == null) {
			lblEhtjqjsgh = new JLabel("도서번호 :");
			lblEhtjqjsgh.setHorizontalAlignment(SwingConstants.RIGHT);
			lblEhtjqjsgh.setForeground(Color.BLUE);
			lblEhtjqjsgh.setBounds(-4, 22, 67, 15);
		}
		return lblEhtjqjsgh;
	}
	private JLabel getLabel_9() {
		if (label_9 == null) {
			label_9 = new JLabel("도  서  명 :");
			label_9.setHorizontalAlignment(SwingConstants.RIGHT);
			label_9.setForeground(Color.BLUE);
			label_9.setBounds(-4, 51, 67, 15);
		}
		return label_9;
	}
	private JLabel getLabel_10() {
		if (label_10 == null) {
			label_10 = new JLabel("저        자 :");
			label_10.setHorizontalAlignment(SwingConstants.RIGHT);
			label_10.setBounds(-4, 80, 67, 15);
		}
		return label_10;
	}
	private JLabel getLabel_11() {
		if (label_11 == null) {
			label_11 = new JLabel("출  판  사 :");
			label_11.setHorizontalAlignment(SwingConstants.RIGHT);
			label_11.setBounds(-4, 109, 67, 15);
		}
		return label_11;
	}
	private JLabel getLabel_12() {
		if (label_12 == null) {
			label_12 = new JLabel("출  판  일 :");
			label_12.setHorizontalAlignment(SwingConstants.RIGHT);
			label_12.setBounds(-4, 138, 67, 15);
		}
		return label_12;
	}
	private JTextField getTxtNo() {
		if (txtNo == null) {
			txtNo = new JTextField();
			txtNo.setEnabled(false);
			txtNo.setColumns(10);
			txtNo.setBounds(75, 17, 187, 25);
		}
		return txtNo;
	}
	private JTextField getTxtName() {
		if (txtName == null) {
			txtName = new JTextField();
			txtName.setColumns(10);
			txtName.setBounds(75, 46, 187, 25);
		}
		return txtName;
	}
	private JTextField getTxtAuthor() {
		if (txtAuthor == null) {
			txtAuthor = new JTextField();
			txtAuthor.setColumns(10);
			txtAuthor.setBounds(75, 75, 187, 25);
		}
		return txtAuthor;
	}
	private JTextField getTxtPublisher() {
		if (txtPublisher == null) {
			txtPublisher = new JTextField();
			txtPublisher.setColumns(10);
			txtPublisher.setBounds(75, 104, 187, 25);
		}
		return txtPublisher;
	}
	private JLayeredPane getLayeredPane_2() {
		if (layeredPane_2 == null) {
			layeredPane_2 = new JLayeredPane();
			layeredPane_2.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null), "\uC791\uC131\uC790", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
			layeredPane_2.setBounds(410, 369, 274, 81);
			layeredPane_2.add(getLabel_3_1());
			layeredPane_2.add(getComboBox_2());
			layeredPane_2.add(getLabel_1());
			layeredPane_2.add(getDatePicker_1());
			layeredPane_2.add(getTxtRdate());
		}
		return layeredPane_2;
	}
	private JLabel getLabel_3_1() {
		if (label_3 == null) {
			label_3 = new JLabel("관  리  자 :");
			label_3.setForeground(Color.BLUE);
			label_3.setHorizontalAlignment(SwingConstants.RIGHT);
			label_3.setBounds(-4, 22, 67, 15);
		}
		return label_3;
	}
	private JComboBox getComboBox_2() {
		if (comboBox_2 == null) {
			comboBox_2 = new JComboBox();
			comboBox_2.setBounds(75, 17, 187, 25);
		}
		return comboBox_2;
	}
	private JLabel getLabel_4_1() {
		if (label_4 == null) {
			label_4 = new JLabel("<html><center>이미지를<br>추가하려면<br>클릭하세요</center></html>", SwingConstants.CENTER);
			label_4.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
			label_4.setBounds(12, 282, 100, 100);
		}
		return label_4;
	}
	private JTextField getTxtBig() {
		if (txtBig == null) {
			txtBig = new JTextField();
			txtBig.setEnabled(false);
			txtBig.setColumns(10);
			txtBig.setBounds(75, 17, 187, 25);
		}
		return txtBig;
	}
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("등  록  일 :");
			label_1.setHorizontalAlignment(SwingConstants.RIGHT);
			label_1.setForeground(Color.BLACK);
			label_1.setBounds(-4, 52, 67, 15);
		}
		return label_1;
	}
	private JLabel getLabel_5() {
		if (label_5 == null) {
			label_5 = new JLabel("총  권  수 :");
			label_5.setHorizontalAlignment(SwingConstants.RIGHT);
			label_5.setBounds(-4, 167, 67, 15);
		}
		return label_5;
	}
	private JSpinner getSpinnerTvolume() {
		if (spinnerTvolume == null) {
			spinnerTvolume = new JSpinner();
			spinnerTvolume.addChangeListener(new ChangeListener() {
				public void stateChanged(ChangeEvent e) {
					
					// 총 권수를 수정할 경우 보유권수 자동으로 수정
					// 보유권수가 0권 이하로 내려가지 않도록 설정
					
					if(Integer.parseInt(spinnerTvolume.getValue().toString()) != tVolume){
						volume = Integer.parseInt(spinnerVolume.getValue().toString()) 
							   + Integer.parseInt(spinnerTvolume.getValue().toString()) 
							   - tVolume;
						if(volume == -1){
							volume++;
							spinnerTvolume.setValue(tVolume);
							spinnerVolume.setValue(volume);
						}else{
							tVolume = Integer.parseInt(spinnerTvolume.getValue().toString());
							spinnerVolume.setValue(volume);
						}
					}
				}
			});
			spinnerTvolume.setEnabled(false);
			spinnerTvolume.setModel(new SpinnerNumberModel(new Integer(1), new Integer(1), null, new Integer(1)));
			spinnerTvolume.setBounds(75, 162, 187, 25);
		}
		return spinnerTvolume;
	}
	private JLabel getLabel_6() {
		if (label_6 == null) {
			label_6 = new JLabel("대여가능 :");
			label_6.setHorizontalAlignment(SwingConstants.RIGHT);
			label_6.setBounds(-4, 196, 67, 15);
		}
		return label_6;
	}
	private JSpinner getSpinnerVolume() {
		if (spinnerVolume == null) {
			spinnerVolume = new JSpinner();
			spinnerVolume.setEnabled(false);
			spinnerVolume.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
			spinnerVolume.setBounds(75, 191, 187, 25);
		}
		return spinnerVolume;
	}
	private JDatePickerImpl getDatePicker(){
		if (datePicker == null) {
			UtilDateModel uModel = new UtilDateModel();
			JDatePanelImpl datePanel = new JDatePanelImpl(uModel);
			datePicker = new JDatePickerImpl(datePanel);
			datePicker.setBorder(null);
			
			datePicker.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					txtPdate.setText(sd.format((Date)datePicker.getModel().getValue()));
				}
			});
			datePicker.getJFormattedTextField().setVisible(false);
			datePicker.setSize(44, 27);
			datePicker.setLocation(217, 133);
			
		}
		return datePicker;
	}
	private JDatePickerImpl getDatePicker_1(){
		if (datePicker1 == null) {
			UtilDateModel uModel = new UtilDateModel();
			JDatePanelImpl datePanel = new JDatePanelImpl(uModel);
			datePicker1 = new JDatePickerImpl(datePanel);
			datePicker1.setBorder(null);
			
			datePicker1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					txtRdate.setText(sd.format((Date)datePicker1.getModel().getValue()));
				}
			});
			datePicker1.getJFormattedTextField().setVisible(false);
			datePicker1.setSize(45, 27);
			datePicker1.setLocation(217, 46);
			
		}
		return datePicker1;
	}
	private JTextField getTxtPdate() {
		if (txtPdate == null) {
			txtPdate = new JTextField();
			txtPdate.setBounds(75, 133, 142, 25);
			txtPdate.setColumns(10);
		}
		return txtPdate;
	}
	private JTextField getTxtRdate() {
		if (txtRdate == null) {
			txtRdate = new JTextField();
			txtRdate.setBounds(75, 47, 142, 25);
			txtRdate.setColumns(10);
		}
		return txtRdate;
	}
}